{extend name="default/base/base_seller" /}
{block name="seller_main"}



<div class="dssc-form-default">
    <form id="chain_form" enctype="multipart/form-data" method="post" >
        {if $Request.action=='add'}
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_name}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_name}{/present}" name="chain_name" id="chain_name" class="w200 text"><span></span>
                <p class="hint"></p>
            </dd>
        </dl>
        {/if}
        <dl>
            <dt>{if $Request.action=='add'}<i class="required">*</i>{/if}{$Think.lang.chain_passwd}{$Think.lang.ds_colon}</dt>
            <dd><input type="password" value="" name="chain_passwd" id="chain_passwd" class="w200 text"><span></span>
                <p class="hint">{if $Request.action=='edit'}{$Think.lang.chain_passwd_tips}{/if}</p>
            </dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_addressname}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_addressname}{/present}" name="chain_addressname" id="chain_addressname" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_truename}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_truename}{/present}" name="chain_truename" id="chain_truename" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_mobile}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_mobile}{/present}" name="chain_mobile" id="chain_mobile" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt>{$Think.lang.chain_telephony}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_telephony}{/present}" name="chain_telephony" id="chain_telephony" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
         <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_area_info}{$Think.lang.ds_colon}</dt>
            <dd>
                <div {if $Think.config.ds_config.mapak_type eq '2'}onclick="change_map()"{/if}>
                        <input type="hidden" value="{$chain_array.chain_area_2|default=''}" name="chain_area_2" id="_area_2">
                        <input type="hidden" value="{$chain_array.chain_area_3|default=''}" name="chain_area_3" id="_area">
                        <input type="hidden" name="chain_area_info" id="region" value="{$chain_array.chain_area_info|default=''}"/>
                    </div>
                <span></span>
                <p class="hint"></p></dd>
        </dl>
        
        
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_address}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_address}{/present}" name="chain_address" id="chain_address" {if $Think.config.ds_config.mapak_type eq '2'}onkeyup="local.search($(this).val());"{/if} class="w200 text">
                <!--{if $Think.config.ds_config.mapak_type neq '0'}-->
                <input name="chain_longitude" id="longitude" value="{$chain_array.chain_longitude|default=''}" type="hidden" />
                <input name="chain_latitude" id="latitude" value="{$chain_array.chain_latitude|default=''}" type="hidden" />
                <div id="allmap" style="width:530px;height: 350px;margin-top: 20px"></div>
                <!--{/if}-->
                <span></span>
                <p class="hint"></p></dd>
        </dl>
        

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_state}: </dt>
            <dd>
                <input id="chain_state1" name="chain_state" {if !isset($chain_array) || $chain_array.chain_state == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_state1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_state == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_state0" name="chain_state" {if isset($chain_array) && $chain_array.chain_state == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_state0" class="cb-disable {if isset($chain_array) && $chain_array.chain_state == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_if_pickup}: </dt>
            <dd>
                <input id="chain_if_pickup1" name="chain_if_pickup" {if !isset($chain_array) || $chain_array.chain_if_pickup == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_if_pickup1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_if_pickup == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_if_pickup0" name="chain_if_pickup" {if isset($chain_array) && $chain_array.chain_if_pickup == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_if_pickup0" class="cb-disable {if isset($chain_array) && $chain_array.chain_if_pickup == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_if_collect}: </dt>
            <dd>
                <input id="chain_if_collect1" name="chain_if_collect" {if !isset($chain_array) || $chain_array.chain_if_collect == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_if_collect1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_if_collect == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_if_collect0" name="chain_if_collect" {if isset($chain_array) && $chain_array.chain_if_collect == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_if_collect0" class="cb-disable {if isset($chain_array) && $chain_array.chain_if_collect == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>

        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_submit}">
        </div>
    </form>
</div>
<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<!--{if $Think.config.ds_config.mapak_type eq '1'}-->
<script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode:"{$Think.config.ds_config.gaode_jscode}",
        }
</script>
<script type="text/javascript" src="//webapi.amap.com/maps?v=2.0&key={$Think.config.ds_config.gaode_ak}"></script>
<!--{/if}-->
<!--{if $Think.config.ds_config.mapak_type eq '2'}-->
<script type="text/javascript" src="{$Think.HTTP_TYPE}api.map.baidu.com/api?v=2.0&ak={$Think.config.ds_config.baidu_ak}"></script>
<!--{/if}-->

<script>
    var local;
    var map;
    var lst_name='';

    function change_map(){
        var name=$("#region").val();

        if(name!='' && lst_name!=name){
            lst_name=name;
            map.setCurrentCity(name);
            map.centerAndZoom(name,16);
            map.clearOverlays();
            local.search(name);
        }

    }
    //按钮先执行验证再提交表单
    $(function () {
        $("#region").ds_region();
		var lng = '{$chain_array.chain_longitude|default=""}';
		var lat = '{$chain_array.chain_latitude|default=""}';
		if('{$Think.config.ds_config.mapak_type}' === '1'){
			var map = new AMap.Map("allmap", {
			    resizeEnable: true,
				zoom:15
			});
			if(!lng && !lat){
				var map = new AMap.Map("allmap", {
				    resizeEnable: true,
					zoom:15
				});
				//获取用户所在城市信息
					AMap.plugin("AMap.CitySearch", function () {
					    var citySearch = new AMap.CitySearch();
					    citySearch.getLocalCity(function (status, result) {
					      if (status === "complete" && result.info === "OK") {
					        // 查询成功，result即为当前所在城市信息
					        AMap.plugin("AMap.Geocoder", function () {
					          var geocoder = new AMap.Geocoder({
					            // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
					            city: result.adcode,
					          });
							  geocoder.getLocation(result.city, function(status1, result1) {
								  var location = result1.geocodes[0].location;
									var lng = location.lng;
									var lat = location.lat;
									
									//初始化定位
									var marker = new AMap.Marker({
									    position: new AMap.LngLat(lng, lat),
									    icon: '//api.map.baidu.com/images/marker_red_sprite.png',
										zoom: 15
									});
									map.add(marker);
									document.getElementById("longitude").value = lng;
									document.getElementById("latitude").value = lat;
									map.panTo([lng, lat]);
									
									//搜索定位
									AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
									    var auto = new AMap.AutoComplete({input:"chain_address"});
									    var placeSearch = new AMap.PlaceSearch({
									        map: map
									    });  //构造地点查询类
									    auto.on("select", select);//注册监听，当选中某条记录时会触发
									    function select(e) {
									        placeSearch.setCity(e.poi.adcode);
									        placeSearch.search(e.poi.name);  //关键字查询查询
									    }
									});
									
									//点击定位
									map.on('click', function(e) {
										document.getElementById("longitude").value = e.lnglat.getLng();
										document.getElementById("latitude").value = e.lnglat.getLat();
										if(marker){
											map.remove(marker);
										}
										marker = new AMap.Marker({
										    position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
										    icon: '//api.map.baidu.com/images/marker_red_sprite.png',
										    anchor: 'bottom-center',
											zoom: 15
										});
										map.add(marker);
									});
								});
							  
					        });
							
					      }
					    });
					  });
			}else{
				map.panTo([lng, lat]);
				//初始化定位
				var marker = new AMap.Marker({
				    position: new AMap.LngLat(lng, lat),
				    icon: '//api.map.baidu.com/images/marker_red_sprite.png',
					zoom: 15
				});
				map.add(marker);
				document.getElementById("longitude").value = lng;
				document.getElementById("latitude").value = lat;
				
				//搜索定位
				AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
				    var auto = new AMap.AutoComplete({input:"chain_address"});
				    var placeSearch = new AMap.PlaceSearch({
				        map: map
				    });  //构造地点查询类
				    auto.on("select", select);//注册监听，当选中某条记录时会触发
				    function select(e) {
				        placeSearch.setCity(e.poi.adcode);
				        placeSearch.search(e.poi.name);  //关键字查询查询
				    }
				});
				
				//点击定位
				map.on('click', function(e) {
					document.getElementById("longitude").value = e.lnglat.getLng();
					document.getElementById("latitude").value = e.lnglat.getLat();
					if(marker){
						map.remove(marker);
					}
					marker = new AMap.Marker({
					    position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
					    icon: '//api.map.baidu.com/images/marker_red_sprite.png',
					    anchor: 'bottom-center',
						zoom: 15
					});
					map.add(marker);
				});
			}		 
		}
                if('{$Think.config.ds_config.mapak_type}' === '2'){
			map = new BMap.Map("allmap");
			if(!lng && !lat){
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function (r) {
					if (this.getStatus() == BMAP_STATUS_SUCCESS) {
						var lng = r.point.lng;
						var lat = r.point.lat;
						var point = new BMap.Point(lng, lat);
						map.centerAndZoom(point, 16);
						map.addControl(new BMap.NavigationControl());
						map.enableScrollWheelZoom();
						var marker = new BMap.Marker(point);  // 创建标注
						map.addOverlay(marker);              // 将标注添加到地图中
						marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
						document.getElementById("longitude").value = lng;
						document.getElementById("latitude").value = lat;
	
					} else {
						layer.msg('failed' + this.getStatus());
					}
				}, {enableHighAccuracy: true})
			}else{
				var point = new BMap.Point(lng, lat);
				map.centerAndZoom(point, 16);
				map.addControl(new BMap.NavigationControl());
				map.enableScrollWheelZoom();
				var marker = new BMap.Marker(point);  // 创建标注
				map.addOverlay(marker);              // 将标注添加到地图中
				marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			}
	
	
			var options = {
				onSearchComplete: function(results){
					// 判断状态是否正确
					if (local.getStatus() == BMAP_STATUS_SUCCESS){
						if(results.getCurrentNumPois()>0){
	
							map.clearOverlays();  //清除标注  或者可以把market 放入数组
							var point = new BMap.Point(results.getPoi(0).point.lng , results.getPoi(0).point.lat);
							var marker = new BMap.Marker(point);
							map.centerAndZoom(point, 16);
							map.addOverlay(marker);
							marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	
							document.getElementById("longitude").value = results.getPoi(0).point.lng;
							document.getElementById("latitude").value = results.getPoi(0).point.lat;
	
						}
					}
				}
			};
			local = new BMap.LocalSearch(map, options);
			map.addEventListener("click", function(e){
	//                    alert(e.point.lng + ", " + e.point.lat);
				map.clearOverlays();  //清除标注  或者可以把market 放入数组
				var point = new BMap.Point(e.point.lng , e.point.lat);
				var marker = new BMap.Marker(point);
				map.addOverlay(marker);
				marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	
				document.getElementById("longitude").value = e.point.lng;
				document.getElementById("latitude").value = e.point.lat;
			});
		}
        
        $("#chain_form").validate({
            submitHandler: function (form) {
                ds_ajaxpost('chain_form', 'url', '{:url("seller_chain/index")}');
            },
            errorPlacement: function (error, element) {
                element.nextAll('span').first().after(error);
            },
            rules: {
                chain_name: {
                    required: true,
                    remote: {
                        url: "{:url('seller_chain/ajax',['branch'=>'chain_name'])}",
                        type: 'get',
                        data: {
                            chain_name: function () {
                                return $('#chain_name').val();
                            },
                            id: '{$chain_array.chain_id|default=0}'
                        }
                    }
                },
                chain_mobile: {
                    required: true,
                },
                chain_truename: {
                    required: true,
                },
                chain_passwd: {
                    required: {present name='chain_array'}false{else}true{/present}
                },

            },
            messages: {
                chain_name: {
                    required: '{$Think.lang.chain_name_required}',
                    remote: '{$Think.lang.chain_name_remote}'
                },
                chain_mobile: {
                    required: '{$Think.lang.chain_phone_required}',
                },
                chain_truename: {
                    required: '{$Think.lang.chain_realname_required}',
                },
                chain_passwd: {
                    required: '{$Think.lang.chain_passwd_required}'
                },

            }
        });
    });

</script>





{/block}
